/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.org.jhsystem.consola.image;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.Properties;
import org.apache.commons.lang.text.StrSubstitutor;

/**
 *
 * @author jhuamanv
 */
public class ImageMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        File archivo = null;
        StrSubstitutor strSub = null;
        String plain = null;

        Properties usuario = new Properties();
        usuario.put("nombre",    "Luigi");
        usuario.put("apellidos", "Builder");
        usuario.put("email",     "jhuamanv@reniec.gob.pe");

        try {
            archivo = new File ("../mail.txt");
            InputStream is = new FileInputStream (archivo);

            plain  = fileToString(is,"utf-8");
            strSub = new StrSubstitutor(usuario);
            plain  = strSub.replace(plain);

            System.out.println(plain);

        }catch(Exception e){
            e.printStackTrace();
        }finally{

        }
   }

    private static String fileToString(InputStream input, String encoding) throws IOException {
        StringWriter      sw = new StringWriter();
        InputStreamReader in = new InputStreamReader(input, encoding);

        char[] buffer = new char[1024 * 2];
        int n = 0;
        while (-1 != (n = in.read(buffer))) sw.write(buffer, 0, n);
        return sw.toString();
    }

}
